import ffmpeg

def ts_to_mp4(ts_file_path, mp4_file_path):
    """
    将ts文件转换成MP4格式
    :param ts_file_path: 输入的ts文件路径
    :param mp4_file_path: 输出的mp4文件路径
    """
    try:
        ffmpeg.input(ts_file_path).output(mp4_file_path).run()
        print(f"成功将 {ts_file_path} 转换为 {mp4_file_path}")
    except ffmpeg.Error as e:
        print(f"转换失败: {e}")

# 示例用法
if __name__ == '__main__':
    ts_file = r'D:\code\python\pyjd\videos\1.ts'
    mp4_file = 'output.mp4'
    ts_to_mp4(ts_file, mp4_file)
